package com.czxy.controller;

import com.czxy.domain.Guest;
import com.czxy.domain.GuestVo;
import com.czxy.service.GuestService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/6
 */
@RestController
@RequestMapping("/guest")
public class GuestController {
    @Resource
    private GuestService guestService;

    //查询出所有的酒店 get 直接查询
    @GetMapping("/findAllGuestBook")
    public BaseResult findAllGuestBook(){
        List<Guest> guestList = guestService.findAllGuestBook();
        return BaseResult.ok("查询成功",guestList);
    }

    //查询所有的酒店 复杂查询 含有 分页 + 条件查询
    @PostMapping("/findAllGuest")
    public BaseResult findAllGuest(@RequestBody GuestVo guestVo){
        PageInfo<Guest> pageInfo = guestService.findAllGuest(guestVo);
        return BaseResult.ok("查询成功",pageInfo);
    }

    //添加 酒点 查询出所有的 房间类型
    @GetMapping("/findAllGuestByAdd")
    public BaseResult findAllGuestByAdd(){
        Set<String> strings = guestService.findAllGuestByAdd();
        return BaseResult.ok("查询成功",strings);
    }

    //酒店添加
    @PostMapping("/addGuest")
    public BaseResult addGuest(@RequestBody Guest guest){
        guestService.addGuest(guest);
        return BaseResult.ok("添加成功");
    }

    //订购酒店房间
    @PutMapping("/updateGuest")
    public BaseResult updateGuest(@RequestBody Guest guest){
        guestService.updateGuest(guest);
        return BaseResult.ok("房间预订成功，等待审核");
    }

    //更换房间
    @PutMapping("/changeGuest")
    public BaseResult changeGuest(@RequestBody Guest guest){
        System.out.println(guest);
        guestService.changeGuest(guest);
        return BaseResult.ok("更换房间成功");
    }

    //所有的空闲房间
    @GetMapping("/findAllGuestKX")
    public BaseResult<List<Guest>> findAllGuestKX(){
        List<Guest> guestList = guestService.findAllGuestKX();
        return BaseResult.ok("查询成功",guestList);
    }

    //后台 查询所有客房 状态 1 为已预订
    @PostMapping("/findAllGuestWYYD")
    public BaseResult findAllGuestWYYD(@RequestBody GuestVo guestVo){
        PageInfo<Guest> pageInfo = guestService.findAllGuestWYYD(guestVo);
        return BaseResult.ok("查询成功",pageInfo);
    }

    //后台 查询所有客房 状态 2 为通过审核
    @PostMapping("/findAllGuestWTGSH")
    public BaseResult findAllGuestWTGSH(@RequestBody GuestVo guestVo){
        PageInfo<Guest> pageInfo = guestService.findAllGuestWTGSH(guestVo);
        return BaseResult.ok("查询成功",pageInfo);
    }

    //通过审核
    @PutMapping("/updateGuestByRid/{rid}")
    public BaseResult updateGuestByRid(@PathVariable("rid") Integer rid){
        guestService.updateGuestByRid(rid);
        return BaseResult.ok("审核通过成功");
    }

    //未通过
    @PutMapping("/canceltheorder/{rid}")
    public BaseResult canceltheorder(@PathVariable("rid") Integer rid){
        guestService.canceltheorder(rid);
        return BaseResult.ok("审核未通过");
    }

    //退房
    @PutMapping("/checkoutGuest/{rid}")
    public BaseResult checkoutGuest(@PathVariable("rid") Integer rid){
        guestService.canceltheorder(rid);
        return BaseResult.ok("退房成功");
    }

    //删除房间
    @DeleteMapping("/deleteGuest/{rid}")
    public BaseResult deleteGuest(@PathVariable("rid") Integer rid){
        guestService.deleteGuest(rid);
        return BaseResult.ok("删除房间成功");
    }

    //查询 2 月的 余额 视图
    @GetMapping("/amountofbusiness")
    public BaseResult amountofbusiness(){
        List<Integer> integerList = guestService.amountofbusiness();
        return BaseResult.ok("查询成功",integerList);
    }
}
